UI={}

function UI.Login()
		loveframes.util.RemoveAll();
		
		local login = loveframes.Create("imagebutton")
		login:SetImage("ui/accept.png")
		login:SetText("Login");
		login:SetPos(350, 400)
		login:SizeToImage()
	 
		
		local register = loveframes.Create("imagebutton")
		register:SetImage("ui/add.png")
		register:SetText("Register");
		register:SetPos(450, 400)
		register:SizeToImage()
		
		
		local username = loveframes.Create("textinput")
		username:SetPos(300, 300)
		username:SetWidth(200)
		
		local code = loveframes.Create("textinput")
		code:SetPos(300, 350)
		code:SetWidth(200)
		
		
		login.OnClick = function(object1, x, y)
			local strName=username.text;
			local strCode=code.text;
			--todo name code send
			UI.Lobby()
		end
		
		register.OnClick=function(object2, x, y)
			local registerFrame = loveframes.Create("frame")
			registerFrame:SetName("Register")
			registerFrame:SetWidth(400);
			registerFrame:SetHeight(200);
			registerFrame:Center()
			 
			
			local newNameTxt = loveframes.Create("text",registerFrame)
			newNameTxt:SetPos(20, 50)
			newNameTxt:SetWidth(80)
			newNameTxt:SetText("Name");
			
			local newCode1Txt = loveframes.Create("text",registerFrame)
			newCode1Txt:SetPos(20, 80)
			newCode1Txt:SetWidth(80)
			newCode1Txt:SetText("Code");
			
			local newCode2Txt = loveframes.Create("text",registerFrame)
			newCode2Txt:SetPos(20, 110)
			newCode2Txt:SetWidth(80)
			newCode2Txt:SetText("CodeConfirm");
			
			local newName = loveframes.Create("textinput",registerFrame)
			newName:SetPos(130, 50)
			newName:SetWidth(200)
			
			local newCode1 = loveframes.Create("textinput",registerFrame)
			newCode1:SetPos(130, 80)
			newCode1:SetWidth(200)
			
			local newCode2 = loveframes.Create("textinput",registerFrame)
			newCode2:SetPos(130, 110)
			newCode2:SetWidth(200)
			
			local confirm = loveframes.Create("button", registerFrame)
				confirm:SetWidth(100)
				confirm:SetText("Confirm")
				confirm:Center()
				confirm:SetY(140);
				confirm.OnClick = function(object3, x, y)
					local strName=newName.text;
					local strCode1=newCode1.text;
					local strCode2=newCode2.text;
					if strCode1==strCode2 then
						--todo
						registerFrame:Remove();
						
						--todo name code send
						UI.Lobby()
					else
						local msgBox = loveframes.Create("frame")
						msgBox:SetName("Error!")
						msgBox:SetSize(300, 100)
						msgBox:Center();
						
						local msg = loveframes.Create("text",msgBox)
						msg:SetText("Two code inputed are diffrent");
						msg:SetPos(50,50)
					end;
				end
		end;
end;


function UI.Lobby()
		loveframes.util.RemoveAll();

		local roomList = loveframes.Create("list")
		roomList:SetSize(490, 300)
		roomList:Center();
		
		
		local createRoom = loveframes.Create("button")
		createRoom:SetSize(480, 25)
		createRoom:Center()
		createRoom:SetY(480);
		createRoom:SetText("Create Room")
		createRoom.OnClick = function(object2, x, y)
			local waitngFrame = loveframes.Create("frame")
			waitngFrame:SetName("Matching")
			waitngFrame:SetWidth(400);
			waitngFrame:SetHeight(100);
			waitngFrame:Center()
			local msg = loveframes.Create("text",waitngFrame)
			msg:SetWidth(400)
			msg:SetPos(60,50);
			msg:SetText("Room created,waiting for another player......"); 
			
			--todo send new room
			
			waitngFrame.OnClose = function(object)
				--todo cancel room
				
			end;
		end
		
		
		
		--todo room
		for i=1, 50 do
			local button2 = loveframes.Create("button")
			button2:SetText(i)
			roomList:AddItem(button2)
			button2.OnClick=function(object)
				--todo send join
				UI.Gaming()
				global.state="war"
			end;
		end
	
end;


skill=nil;

function UI.Gaming()
	loveframes.util.RemoveAll();
	
	skill = loveframes.Create("imagebutton")
	skill:SetImage("ui/carlsagan.png")
	skill:SetText("");
	skill:Center();
	skill:SetPos(650,450);
	skill:SetVisible(false);
end;


function UI.ShowSkillIcon(visible)
	skill:SetVisible(visible);
end;